package cloudUser;

import cloudEntity.entity.SmartUserEntity;
import cloudEntity.utils.ResultUtils;
import cloudUser.config.CustomerUserDetailsService;
import cloudUser.mapper.SmartPermissionMapper;
import cloudUser.mapper.SmartRoleMapper;
import cloudUser.mapper.SmartUserMapper;
import cloudUser.util.JwtUtilCustomer;
import cloudUser.util.RedisUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.json.JSONUtil;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;

import java.util.HashMap;
import java.util.Map;


/**
 * @program: Smart School
 * @ClassName test1
 * @description:
 * @author: 陈智博
 * @create: 2025-03-24 17:23
 * @Version 1.0
 **/
@SpringBootTest
public class testApplication {

    @Autowired
    private SmartUserMapper smartUserMapper;

    @Autowired
    private SmartRoleMapper smartRoleMapper;

    @Autowired
    private SmartPermissionMapper smartPermissionMapper;

    @Autowired
    private BCryptPasswordEncoder bCryptPasswordEncoder;

    @Autowired
    private RedisUtil redisUtil;

    @Test
    public void test1()
    {
        SmartUserEntity admin = smartUserMapper.getUserByName("管理员");
        System.out.println(admin);
    }

    @Test
    public void test3()
    {
        String encode = bCryptPasswordEncoder.encode("a123456");
        System.out.println(encode);
    }

    @Test
    public void test4()
    {
        Map<String,Object> hash = new HashMap<>();
        hash.put("username","admin");
        hash.put("password","123456");
        String token = JwtUtilCustomer.createToken(hash, "123456");
        System.out.println(token);
        Map<String, Object> stringObjectMap = JwtUtilCustomer.parseToken(token);

        String o = (String) stringObjectMap.get("username");
        System.out.println("str:"+o);

        stringObjectMap.forEach((i,v)->{
            System.out.println(stringObjectMap.get(v)+":"+stringObjectMap.get(i));
        });

        boolean b = JwtUtilCustomer.verifyToken(token);
        System.out.println(b);

    }

    @Test
    public void test5()
    {
        String encode = new BCryptPasswordEncoder().encode("admin");
        System.out.println(encode);
    }

    @Test
    public void test6()
    {
        boolean matches = new BCryptPasswordEncoder().matches("admin", "$2a$10$MMsyb5JdGsUBR2b6kNM84uwWd6/9FfWORiioqUR3bQNvdCWdX4g5.");
        System.out.println(matches);
    }

    @Test
    public void test7()
    {
//      xi
    }

    @Test
    public void test8()
    {
//        Set<String> permissionByUserId = smartPermissionMapper.getPermissionByUserId(1);
//        for (String s : permissionByUserId) {
//            System.out.println(s);
//        }
    }


    @Test
    public void test9()
    {
        String o1 = (String) redisUtil.get("login1");
        System.out.println(o1);
        CustomerUserDetailsService bean = JSONUtil.toBean(o1, CustomerUserDetailsService.class);
        System.out.println(bean);
    }

    @Test
    public void test10()
    {
//        Set<String> permissionByUserId = smartPermissionMapper.getPermissionByUserId(1);
//        for (String s : permissionByUserId) {
//            System.out.println(s);
//        }
    }
    @Test
    public void test11()
    {
//        ResultUtils<SmartUserEntity> user = authFeignClient.getUser(1L);
//        System.out.println(user);
    }

    @Test
    public void test12()
    {
        String s = IdUtil.simpleUUID();
        System.out.println(s);
    }

    @Test
    public void test13()
    {
        SmartUserEntity userByName = smartUserMapper.getUserByName("admin");
        System.out.println(userByName);
    }

}
